            
class ScratchPadController {
    
    def index = { redirect(action:list,params:params) }

    // the delete, save and update actions only accept POST requests
    def allowedMethods = [delete:'POST', save:'POST', update:'POST']

    def list = {
        if(!params.max) params.max = 10
        [ scratchPadList: ScratchPad.list( params ) ]
    }

    def show = {
        def scratchPad = ScratchPad.get( params.id )

        if(!scratchPad) {
            flash.message = "ScratchPad not found with id ${params.id}"
            redirect(action:list)
        }
        else { return [ scratchPad : scratchPad ] }
    }

    def delete = {
        def scratchPad = ScratchPad.get( params.id )
        if(scratchPad) {
            scratchPad.delete()
            flash.message = "ScratchPad ${params.id} deleted"
            redirect(action:list)
        }
        else {
            flash.message = "ScratchPad not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def edit = {
        def scratchPad = ScratchPad.get( params.id )

        if(!scratchPad) {
            flash.message = "ScratchPad not found with id ${params.id}"
            redirect(action:list)
        }
        else {
            return [ scratchPad : scratchPad ]
        }
    }

    def update = {
        def scratchPad = ScratchPad.get( params.id )
        if(scratchPad) {
            scratchPad.properties = params
            if(!scratchPad.hasErrors() && scratchPad.save()) {
                flash.message = "ScratchPad ${params.id} updated"
                redirect(action:show,id:scratchPad.id)
            }
            else {
                render(view:'edit',model:[scratchPad:scratchPad])
            }
        }
        else {
            flash.message = "ScratchPad not found with id ${params.id}"
            redirect(action:edit,id:params.id)
        }
    }

    def create = {
        def scratchPad = new ScratchPad()
        scratchPad.properties = params
        return ['scratchPad':scratchPad]
    }

    def save = {
        def scratchPad = new ScratchPad(params)
        if(!scratchPad.hasErrors() && scratchPad.save()) {
            flash.message = "ScratchPad ${scratchPad.id} created"
            redirect(action:show,id:scratchPad.id)
        }
        else {
            render(view:'create',model:[scratchPad:scratchPad])
        }
    }
}